#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
/// 获取物体的路径
/// </summary>
public class ToolsHHH 
{

    [MenuItem("GameObject/获取物体路径到粘贴板", false, 2)]
    public static void DebugPath()
    {
        GameObject obj = Selection.activeGameObject;
        string Path = "";
        Path = obj.name.ToString();
        do
        {
            obj = obj.transform.parent.gameObject;
            Path = obj.name.ToString() + "/" + Path;
        } while (obj.transform.parent != null);
        Debug.Log(Path);
        GUIUtility.systemCopyBuffer = Path;
    }
    [MenuItem("Assets/获取当前路径的地址到粘贴板/resources文件夹路径")]
    public static void ResourcesFolder() {
        UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object),SelectionMode.TopLevel);
        var path = AssetDatabase.GetAssetPath(arr[0]);
        path = path.Remove(0, 17);
        Debug.Log(path);
        GUIUtility.systemCopyBuffer = path;
    }
    [MenuItem("Assets/获取当前路径的地址到粘贴板/Assest文件夹路径")]
    public static void AssestFolder()
    {
        UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel);
        var path = AssetDatabase.GetAssetPath(arr[0]);
        Debug.Log(path);
        GUIUtility.systemCopyBuffer = path;
    }



    /// <summary>
    /// 获取物体的路径
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static string GetPath(GameObject obj)
    {
        string Path = "";
        Path = obj.name.ToString();
        do
        {
            obj = obj.transform.parent.gameObject;
            Path = obj.name.ToString() + "/" + Path;
        } while (obj.transform.parent != null);
        return Path;
    }
    /// <summary>
    /// 修改物体及其子物体的层
    /// </summary>
    /// <param name="layerName"></param>
    /// <param name="obj"></param>
    public static void ChangeLayer(string layerName, GameObject obj)
    {
        if (LayerMask.NameToLayer(layerName) == -1)
        {
            Debug.Log(layerName + "不存在");
            return;
        }

        obj.layer = LayerMask.NameToLayer(layerName);
        foreach (Transform child in obj.transform)
        {
            ChangeLayer(layerName, child.gameObject);
            Debug.Log(child.name + "层修改为" + layerName);
        }
    }
    public static string CheckSocketMessage(byte[] data)
    {
        byte checkCount = 0;
        for (int i = 0; i < data.Length - 1; i++)
        {
            checkCount += data[i];
        }

        if (checkCount != data[6])
        {
            return "校验正确";

        }
        else {
            return "校验失败";
        }
        
    }   

    //public static void ChangeCameraSeeLayer(Camera camera) {
    //    camera.
    //}
}

#endif